import { defineStore } from 'pinia'
import { addAttra, detail, getAttractionsList, remove ,updateAttra,removeBatchByAttrIds} from '@/service/attractions/index.js'
import getDate from '@/utils/dateChange.js'
import responseMessage from '@/utils/response.js'

const useAttractionsStore = defineStore('attractions', {
  state: () => ({
    attractionsList: '',
    detail: ''
  }),
  actions: {
    //获取文章列表
    async getAttractionsList(page, size, searchParams) {
      if (searchParams?.searchTime) {
        //改变事件
        const startTime = getDate(searchParams.searchTime[0])
        const endTime = getDate(searchParams.searchTime[1])
        searchParams.searchTime[0] = startTime
        searchParams.searchTime[1] = endTime
      }
      const res = await getAttractionsList(page, size, searchParams)
      console.log('回传的景点信息结果集是===',res)
      this.attractionsList = res.data
      console.log('attractionsList结果集是===',this.attractionsList)
    },
    //新增景点信息
    async addAttractions(addAttractions) {
      const res = await addAttra(addAttractions)
      //responseMessage(res)
      return res
    },
    //修改景点信息
    async updateAttraction(addAttractions) {
      console.log('修改景点信息',addAttractions)
      const res = await updateAttra(addAttractions)
      console.log('修改完了')
      //responseMessage(res)
      return res
    },
    //删除景点  
    async removeAttrById(id) {
      const res = await remove(id)
      responseMessage(res)
    },
    //批量删除景点信息
    async removeBatchByAttractionIds(attrIds) {
      console.log('批量删除景点信息ids',attrIds)
      const res = await removeBatchByAttrIds(attrIds)
      responseMessage(res)
    },
    //景点详情
    async getAttractionDetail(id) {
      console.log('准备查询了')
      const res = await detail(id)
      console.log('详情信息是===',res)
      this.detail = res.data.data
      //responseMessage(res)
      return res
    }
  }
})

export default useAttractionsStore
